package cn.kgc.springcloud.service.impl;

import cn.kgc.springcloud.clients.ClazzClient;
import cn.kgc.springcloud.entity.Clazz;
import cn.kgc.springcloud.vo.GroupVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kgc.springcloud.entity.Group;
import cn.kgc.springcloud.service.GroupService;
import cn.kgc.springcloud.mapper.GroupMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author mengshun
* @description 针对表【t_group】的数据库操作Service实现
* @createDate 2025-01-17 09:31:27
*/
@Service
public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group>implements GroupService{


    @Resource
    private ClazzClient clazzClient;

    @Override
    public List<GroupVO> groupVOList() {

        List<Group> groups = baseMapper.selectList(null);

        List<GroupVO> groupVOS = groups.stream().map(group -> {
            GroupVO groupVO = new GroupVO();
            BeanUtils.copyProperties(group, groupVO);
            Integer clazzid = group.getClazzid();
            // 发送http请求 根据clazzId获取班级详细信息
            Clazz clazz= clazzClient.getClazzById(clazzid);
            groupVO.setClazz(clazz);
            return groupVO;
        }).collect(Collectors.toList());


        return groupVOS;
    }
}




